package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.User;
import com._51cto.healthy.service.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserRoleController {
    //角色管理查询所有

    @DubboReference
    private UserService userService;

    @GetMapping("/page/{pageSize}/{pageNum}")
    public R queryUserRole(@RequestParam(value = "query",required = false/*表示参数不是必填项*/) String query,
                           @PathVariable("pageNum") Integer pageNum,
                           @PathVariable("pageSize") Integer pageSize){
        P<User> userP = userService.queryUserRole(query,pageNum, pageSize);
        return R.success(userP,"成功");
    }

    @PutMapping("/uppsd")
    public R upPassword(@RequestBody User user){
        userService.upPassword(user);
        return R.success("密码修改成功");
    }

    @PostMapping
    public R insertUserRole(@RequestBody User user){
        userService.insertInto(user);
        return R.success("添加成功");
    }

    @PutMapping
    public R updateUserRole(@RequestBody User user){
        userService.updateUserRole(user);
        return R.success("修改成功");
    }

    @DeleteMapping("/{id}")
    public R deleteUserRole(@PathVariable("id") Integer id){
        userService.deleteUserRole(id);
        return R.success("删除成功");

    }

}
